<template>
  <div class="addAddress_r">
    <AddressInfo ref="addressInfo"></AddressInfo>
    <w-button type="primary"  @click="handleAdd()" plain class="addAddress_btn">添加地址</w-button>
  </div>
</template>

<script>
import AddressInfo from "../components/AddressInfo.vue";
export default {
  name: "AddAddress",
  components: { AddressInfo },
  methods: {
    handleAdd() {
      let uid = localStorage.getItem("uid");
      if (
        this.$refs.addressInfo.address === "" &&
        this.$refs.addressInfo.name === "" &&
        this.$refs.addressInfo.acity === "" &&
        this.$refs.addressInfo.phone === ""
      ) {
        this.$alert("请输入完整", "提示", {
          confirmButtonText: "确定",
        });
        
      }else {
        this.$axios({
          method: "POST",
          url: "http://1.15.170.222:88/api/manage/address/insert",
          data: {
            uid: uid,
            address:
              this.$refs.addressInfo.acity + this.$refs.addressInfo.address,
            name: this.$refs.addressInfo.name,
            phone: this.$refs.addressInfo.phone,
          },
        }).then((response) => {
          console.log(response);
          let code = response.data.code;
          if (code === 500) {
            this.$alert("服务器内部错误", "提示", {
              confirmButtonText: "确定",
            });
          } else {
            this.$alert("添加成功", "提示", {
              confirmButtonText: "确定",
            });
            this.$router.push({
              name: "dizhi",
            });
          }
        });
      }
    },
  },
};
</script>

<style>
.addAddress_r {
  padding-top: 80px;
  display: flex;
  flex-direction: column;
  width: 1050px;
  height: 680px;
}
.add_input {
  display: flex;
  flex-direction: column;
  margin: 0 auto;
}
.addAddress_btn {
  width: 100px;
  margin: 5px auto;
}
</style>
